package com.es.api;

import com.es.api.enums.SystemResultTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 描述:
 * Old-AgeCareSystem-
 *
 * @author Derek
 * @create 2021-12-06 10:16
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SystemResult<T> {

    private Integer code;
    private String msg;
    private Long count;
    private boolean success;
    private T data;

    public static SystemResult success(Object data){
        SystemResult result = new SystemResult();
        result.setData(data);
        result.setCode(SystemResultTypeEnum.SUCCESS.getCode());
        result.setMsg(SystemResultTypeEnum.SUCCESS.getMsg());
        return result;
    }

    public static SystemResult fail(Object data){
        SystemResult result = new SystemResult();
        result.setData(data);
        result.setCode(SystemResultTypeEnum.FAIL.getCode());
        result.setMsg(SystemResultTypeEnum.FAIL.getMsg());
        result.setCount(0L);
        return result;
    }
    public static SystemResult empty(Object data){
        SystemResult result = new SystemResult();
        result.setData(data);
        result.setCode(SystemResultTypeEnum.FAIL.getCode());
        result.setMsg("暂无数据");
        result.setCount(0L);
        return result;
    }

    public boolean getSuccess(){
        return SystemResultTypeEnum.SUCCESS.getCode()==code;
    }
}
